config_template = '''        ("{io_name}", {{
            "name": "/runtime1/param/{io_name}_blow",
            "io_diagnosis": {{
                "name": "{chinese_name}",
                "diagnosis": "{io_name}_diagnosis",
                "read": {read_io_name},
                "physical": "{io_name}_physical",
                "write": "{io_name}"
            }}
        }}),
        ("{io_name}_physical", {{
            "name": "/runtime1/signal/out_{io_name}_state",
        }}),
        ("{io_name}_diagnosis", {{
            "name": "/runtime1/param/out_{io_name}_diagnosis",
        }}),
'''

# 定义io列表
# (io的英文名， io的中文名， 是否是输入io)
io_name_list = [("ccd_open", "ccd开门", False), ("align_tool_1", "对刀1", True)]

# 生成io配置列表
result = []
for e_name, c_name, b_is_input in io_name_list:
    if not b_is_input:
        result.append(config_template.format(io_name=e_name, chinese_name=c_name, read_io_name="None"))
    else:
        result.append(config_template.format(io_name=e_name, chinese_name=c_name, read_io_name="\"{}\"".format(e_name)))

# 生成配置文件
txt_result = "".join(result)
with open("io_configs.txt", "w", encoding="utf-8") as f:
    f.write(txt_result)

print("generator ok")
